package com.muyu.system.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.system.domain.DmShoppingComment;
import com.muyu.system.service.IDmShoppingCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品评价Controller
 *
 * @author ruoyi
 * @date 2025-01-18
 */
@RestController
@RequestMapping("/comment")
public class DmShoppingCommentController extends BaseController {
    @Autowired
    private IDmShoppingCommentService dmShoppingCommentService;

    /**
     * 查询商品评价列表
     */
    //@RequiresPermissions("system:comment:list")
    @GetMapping("/list")
    public Result list(DmShoppingComment dmShoppingComment) {
        startPage();
        List<DmShoppingComment> list = dmShoppingCommentService.selectDmShoppingCommentList(dmShoppingComment);
        return getDataTable(list);
    }

    /**
     * 导出商品评价列表
     */
    //@RequiresPermissions("system:comment:export")
    @Log(title = "商品评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmShoppingComment dmShoppingComment) {
        List<DmShoppingComment> list = dmShoppingCommentService.selectDmShoppingCommentList(dmShoppingComment);
        ExcelUtil<DmShoppingComment> util = new ExcelUtil<DmShoppingComment>(DmShoppingComment.class);
        util.exportExcel(response, list, "商品评价数据");
    }

    /**
     * 获取商品评价详细信息
     */
    //@RequiresPermissions("system:comment:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id) {
        return success(dmShoppingCommentService.selectDmShoppingCommentById(id));
    }

    /**
     * 新增商品评价
     */
    //@RequiresPermissions("system:comment:add")
    @Log(title = "商品评价", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DmShoppingComment dmShoppingComment) {
        return toAjax(dmShoppingCommentService.insertDmShoppingComment(dmShoppingComment));
    }

    /**
     * 修改商品评价
     */
    //@RequiresPermissions("system:comment:edit")
    @Log(title = "商品评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DmShoppingComment dmShoppingComment) {
        return toAjax(dmShoppingCommentService.updateDmShoppingComment(dmShoppingComment));
    }

    /**
     * 删除商品评价
     */
    //@RequiresPermissions("system:comment:remove")
    @Log(title = "商品评价", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids) {
        return toAjax(dmShoppingCommentService.deleteDmShoppingCommentByIds(ids));
    }
}
